package com.wangjiacai.hql.condition.where;


import com.wangjiacai.hql.condition.Condition;
import com.wangjiacai.util.HqlUtil;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Target({ElementType.FIELD,ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Condition(condition = Equal.EqualCondition.class,column =Equal.EqualCondition.class )
public @interface Equal{

    String column() default "";

    String hql() default "";

    class EqualCondition implements Condition.Where<Equal,Object>, Condition.Column<Equal> {
        @Override
        public String where(Equal equal,String property,String column,Object obj,Object value) {
            return equal.hql().equals("")?column+" = :"+property:column+" = ("+ HqlUtil.parseHql(equal.hql(),obj)+")";
        }

        @Override
        public String column(Equal equal, String property) {
            return equal.column().equals("")?property:equal.column();
        }
    }

}
